//
//  CyCStandardCell.m
//  Cycling
//
//  Created by chijianguo on 2023/3/12.
//

#import "CyCStandardCell.h"
#import "Public.h"

@interface CyCStandardCell ()
@property (nonatomic , strong) UIView *shadeView;
@end


@implementation CyCStandardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
        self.isUserEnable = YES;
    }
    return self;
}

- (void)setupUI{
    self.imView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imView];
    [self.imView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(MARGIN_MIDDLE);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(MARGIN_MAX, MARGIN_MAX));
    }];

    self.titleLB = [[UILabel alloc] init];
    self.titleLB.font = FONT_SECONDARY_TITLE;
    self.titleLB.textColor = COLOR_BLACK;
    [self.contentView addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(MARGIN_MIDDLE);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    
    self.subTitleLB = [[UILabel alloc] init];
    self.subTitleLB.font = FONT_BODY_16;
    self.subTitleLB.textColor = COLOR_SIMPLEBLACK;
    self.subTitleLB.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.subTitleLB];
    [self.subTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    
    self.selectImView = [[UIImageView alloc] init];
    self.selectImView.image = [UIImage imageNamed:@"icon_not_select"];
    [self.contentView addSubview:self.selectImView];
    [self.selectImView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(MARGIN_MAX, MARGIN_MAX));
    }];
    
    self.arrowIMView = [[UIImageView alloc] init];
    self.arrowIMView.image = [UIImage imageNamed:@"arrow"];
    [self.contentView addSubview:self.arrowIMView];
    [self.arrowIMView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(MARGIN_MAX, MARGIN_MAX));
    }];

    self.shadeView = [[UIView alloc] init];
    self.shadeView.backgroundColor = COLOR_SHADE;
    [self.contentView addSubview:self.shadeView];
    [self.shadeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView).offset(0);
    }];
    self.shadeView.hidden = YES;

}

-(void)setCellType:(CycStandardCellType)cellType {
    _cellType = cellType;
    
    if (cellType == CycStandardCellTypeDefult) {
        self.imView.hidden = NO;
        self.selectImView.hidden = YES;
        self.arrowIMView.hidden = NO;
        [self.imView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        }];
        [self.titleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MIDDLE+MARGIN_MAX+MARGIN_MAX);
        }];
        [self.arrowIMView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        }];
        [self.subTitleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX*2);
        }];
    }
    if (cellType == CycStandardCellTypeTitle) {
        self.imView.hidden = YES;
        self.selectImView.hidden = YES;
        self.arrowIMView.hidden = YES;
        [self.titleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        }];
        [self.subTitleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        }];
    }

    if (cellType == CycStandardCellTypeArrow) {
        self.imView.hidden = YES;
        self.selectImView.hidden = YES;
        self.arrowIMView.hidden = NO;
        [self.titleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        }];
        [self.arrowIMView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX);
        }];
        [self.subTitleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MIN-MARGIN_MAX-MARGIN_MAX);
        }];
    }
    if (cellType == CycStandardCellTypeSelect) {
        self.imView.hidden = YES;
        self.selectImView.hidden = NO;
        self.arrowIMView.hidden = YES;
        [self.titleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        }];
        [self.selectImView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX-1);
        }];
        [self.subTitleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MIN-MARGIN_MAX-MARGIN_MAX);
        }];
    }
    if (cellType == CycStandardCellTypeSelectAndIM) {
        self.imView.hidden = NO;
        self.selectImView.hidden = NO;
        self.arrowIMView.hidden = YES;
        [self.imView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MAX);
        }];
        [self.titleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MARGIN_MIDDLE+MARGIN_MAX+MARGIN_MAX);
        }];
        [self.selectImView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MAX-1);
        }];
        [self.subTitleLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-MARGIN_MIN-MARGIN_MAX-MARGIN_MAX);
        }];
    }
}
- (void)setIsUserEnable:(BOOL)isUserEnable {
    _isUserEnable = isUserEnable;
    self.shadeView.hidden = isUserEnable;
    self.userInteractionEnabled = isUserEnable;
}

-(void)setIsChoose:(BOOL)isChoose {
    _isChoose = isChoose;
    if (isChoose) {
        self.selectImView.image = [UIImage imageNamed:@"icon_select"];
    }else {
        self.selectImView.image = [UIImage imageNamed:@"icon_not_select"];
    }
}

@end
